package com.ruoyi.web.controller.store;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.major.domain.StuMagor;
import com.ruoyi.store.domain.StuExamDetail;
import com.ruoyi.store.domain.StuHisExam;
import com.ruoyi.store.domain.StuPaper;
import com.ruoyi.store.domain.StuUserAnswer;
import com.ruoyi.store.service.IStuExamDetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/online/detail")
public class StuHisDetailController extends BaseController {
    @Resource
    private IStuExamDetailService stuExamDetailService;



    @GetMapping("/list")
    public TableDataInfo list(StuExamDetail stuExamDetail)
    {
        startPage();
//        stuExamDetail.setCreateBy(getUsername());
        List<StuExamDetail> list = stuExamDetailService.selectStuExamDetailList(stuExamDetail);
        return getDataTable(list);
    }

    @GetMapping("/stulist")
    public TableDataInfo userlist(StuExamDetail stuExamDetail)
    {
        startPage();
        Long userId = getUserId();
        List<StuExamDetail> list = stuExamDetailService.selectStuExamDetailListByUserId(userId);
        return getDataTable(list);
    }

    @GetMapping("/marklist")
    @PreAuthorize("@ss.hasPermi('online:history:mark')")
    public AjaxResult selectPaperQuestionByPaperList(Long userId,Long paperId){
        startPage();
        return  AjaxResult.success(stuExamDetailService.selectStuHisPaperByUserId(userId,paperId));
    }

    //显示历史试卷
    @GetMapping("/showHisDeatil")
    public AjaxResult selectHisPaper(Long userId,Long paperId){
        startPage();
        return  AjaxResult.success(stuExamDetailService.selectStuHisPaper(userId,paperId));
    }

    @GetMapping("/scoreDeatil")
    public AjaxResult selectScore(Long userId,Long paperId){
        startPage();
        return  AjaxResult.success(stuExamDetailService.selectStuExamDetailByUserIdPaperId(userId,paperId));
    }

    @PostMapping("/addMark")
    public AjaxResult addMark(@RequestBody StuHisExam stuHisExam){
        return  AjaxResult.success(stuExamDetailService.addMark(stuHisExam));
    }


    @Log(title = "答卷管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StuExamDetail stuExamDetail)
    {
        List<StuExamDetail> list = stuExamDetailService.selectStuExamDetailList(stuExamDetail);
        ExcelUtil<StuExamDetail> util = new ExcelUtil<StuExamDetail>(StuExamDetail.class);
        util.exportExcel(response, list, "答卷信息");
    }
}
